package gui;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;



public class Gui extends JDialog implements WindowListener{
	
	private double taxaDeChegadaEmHora;
	private int numeroDeCarros;	
	private double tempoDeAluguelEmDias;
	private double tempoDeAtendimentoEmHora;
	private int confidenceLevel;
	
	private JSpinner spinner1;
	private JSpinner spinner2;
	private JSpinner spinner3;
	private JSpinner spinner4;
	private JSpinner spinner5;
	private JSpinner spinner6;
	
	public Gui() {
		JPanel mainPanel = createPanel();
		setContentPane(mainPanel);
		pack();
		setModal(true);
		setVisible(true);
	}

	private JPanel createPanel() {
		JPanel main = new JPanel();
		main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));

		//opt2
		JPanel opt1Panel = new JPanel();
		opt1Panel.setLayout(new BoxLayout(opt1Panel, BoxLayout.LINE_AXIS));
		
        JLabel jLabel1 = new JLabel();
        spinner1 = new JSpinner(new SpinnerNumberModel(1, 0.0, 10000.0, 0.1) );
        jLabel1.setText("Taxa media de chegada de clientes (clientes/h):");
        
        opt1Panel.add(jLabel1);
        opt1Panel.add(Box.createRigidArea(new Dimension(10, 0)));
        opt1Panel.add(spinner1);

        main.add(opt1Panel);
        main.add(Box.createRigidArea(new Dimension(0,5)));

        
        //opt2
		JPanel opt2Panel = new JPanel();
		opt2Panel.setLayout(new BoxLayout(opt2Panel, BoxLayout.LINE_AXIS));
		
        JLabel jLabel2 = new JLabel();
        spinner2 = new JSpinner(new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1));
        jLabel2.setText("Numero de carros:");
        
        opt2Panel.add(jLabel2);
        opt2Panel.add(Box.createRigidArea(new Dimension(10, 0)));
        opt2Panel.add(spinner2);

        main.add(opt2Panel);
        main.add(Box.createRigidArea(new Dimension(0,5)));
        
        //opt3
		JPanel opt3Panel = new JPanel();
		opt3Panel.setLayout(new BoxLayout(opt3Panel, BoxLayout.LINE_AXIS));
		
        JLabel jLabel3 = new JLabel();
        spinner3 = new JSpinner(new SpinnerNumberModel(1, 0.0, 10000.0, 0.1));
        jLabel3.setText("Tempo medio de aluguel (dias):");
        
        opt3Panel.add(jLabel3);
        opt3Panel.add(Box.createRigidArea(new Dimension(10, 0)));
        opt3Panel.add(spinner3);

        main.add(opt3Panel);
        main.add(Box.createRigidArea(new Dimension(0,5)));
        
        //opt4
		JPanel opt4Panel = new JPanel();
		opt4Panel.setLayout(new BoxLayout(opt4Panel, BoxLayout.LINE_AXIS));
		
        JLabel jLabel4 = new JLabel();
        spinner4 = new JSpinner(new SpinnerNumberModel(1, 0.0, 10000.0, 0.1));
        jLabel4.setText("Tempo medio de atendimento (horas):");
        
        opt4Panel.add(jLabel4);
        opt4Panel.add(Box.createRigidArea(new Dimension(10, 0)));
        opt4Panel.add(spinner4);

        main.add(opt4Panel);
        main.add(Box.createRigidArea(new Dimension(0,5)));
        
        //opt5
		JPanel opt5Panel = new JPanel();
		opt5Panel.setLayout(new BoxLayout(opt5Panel, BoxLayout.LINE_AXIS));
		
        JLabel jLabel5 = new JLabel();
        spinner5 = new JSpinner(new SpinnerNumberModel(95, 0, 100, 1));
        jLabel5.setText("TThe confidence level for which the confidence interval will be calculated (%):");
        
        opt5Panel.add(jLabel5);
        opt5Panel.add(Box.createRigidArea(new Dimension(10, 0)));
        opt5Panel.add(spinner5);
        
        main.add(opt5Panel);
        main.add(Box.createRigidArea(new Dimension(0,5)));
        
        //btn
		JPanel optPanel = new JPanel();
		optPanel.setLayout(new BoxLayout(optPanel, BoxLayout.LINE_AXIS));
		
        JButton simular = new JButton("Simular");
        simular.addActionListener(
        	    new ActionListener() {

					public void actionPerformed(ActionEvent arg0) {
						simular();
					}

        	    }
        	);

        
        optPanel.add(simular);

        main.add(optPanel);
		
		return main;
	}
	
	private void simular() {
		taxaDeChegadaEmHora = (Double) this.spinner1.getValue();
		numeroDeCarros = (Integer) this.spinner2.getValue();
		tempoDeAluguelEmDias = (Double) this.spinner3.getValue();
		tempoDeAtendimentoEmHora = (Double) this.spinner4.getValue();
		confidenceLevel = (Integer) this.spinner5.getValue();
		setVisible(false);
	}

	
	public double getTaxaDeChegadaEmHora() {
		return taxaDeChegadaEmHora;
	}

	public int getNumeroDeCarros() {
		return numeroDeCarros;
	}

	public double getTempoDeAluguelEmDias() {
		return tempoDeAluguelEmDias;
	}

	public double getTempoDeAtendimentoEmHora() {
		return tempoDeAtendimentoEmHora;
	}

	public int getConfidenceLevel() {
		return confidenceLevel;
	}

	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowClosed(WindowEvent arg0) {
		System.exit(0);
	}

	public void windowClosing(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
